# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=wget
pkgver=1.16.3
pkgrel=1
pkgdesc="A network utility to retrieve files from the Web"
arch=('i686' 'x86_64')
url="http://www.gnu.org/software/wget/wget.html"
license=('GPL3')
groups=('base-devel')
depends=('gcc-libs' 'libiconv' 'libidn' 'libintl' 'libpcre' 'libuuid' 'openssl' 'zlib')
makedepends=('gettext-devel' 'libidn-devel' 'libuuid-devel' 'openssl-devel' 'pcre-devel' 'zlib-devel')
checkdepends=('perl-HTTP-Daemon' 'perl-IO-Socket-SSL')
optdepends=('ca-certificates: HTTPS downloads')
backup=('etc/wgetrc')
install=wget.install
source=(ftp://ftp.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.xz{,.sig}
        1.13.4-sysconfdir.patch
        wget-1.14-msys2.patch
        fix-gettext-version.patch)
sha1sums=('a7d24a8512720893b0a8c5c436f324e9ed43874d'
          'SKIP'
          'da9a76951c305b456931c7ed462c12b99fd94d79'
          '6ce8d54edf11cef9223780e2c249231f331194f9'
          'c512b77d9f2e56f9870633be54cf2abd156280c6')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  patch -p2 -i "${srcdir}/1.13.4-sysconfdir.patch"
  patch -p1 -i "${srcdir}/wget-1.14-msys2.patch"
  patch -p1 -i "${srcdir}/fix-gettext-version.patch"

  autoreconf -fiv
  cat >> doc/sample.wgetrc <<EOF

# default root certs location
ca_certificate=/usr/ssl/certs/ca-bundle.crt
EOF
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  ./configure --build=${CHOST} \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    --with-ssl=openssl \
    --without-libiconv-prefix \
    --without-libintl-prefix \
    --without-libpth-prefix \
    --without-libssl-prefix \
    --without-libgnutls-prefix

  make
}

check() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make check
}

package() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make DESTDIR="${pkgdir}" install
}
